package com.baizhi.cmfz.controller;


import com.baizhi.cmfz.annotation.LogAnnotation;
import com.baizhi.cmfz.entiy.User;
import com.baizhi.cmfz.service.ThreadUserService;
import com.baizhi.cmfz.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("user")
public class UserController {


    @Autowired
    private UserService service;

    @Autowired
    private ThreadUserService threadUserService;


    @RequestMapping("/getUserByPage")
    @ResponseBody
    @LogAnnotation("查看用户")
    public Map getUserByPage(int page,int rows){

        return service.getUserByPage(page,rows);
    }

    @RequestMapping("update")
    @ResponseBody
    @LogAnnotation("更新用户")
    public Map update(User user){
        HashMap map = new HashMap();

        try {
            service.update(user);
            map.put("isUpdate",true);
        } catch (Exception e) {
            map.put("isUpdate",false);
            e.printStackTrace();
        }
        return map;
    }
    @RequestMapping("selectBySexCount")
    @ResponseBody
    public List<Map> selectBySexCount(){
        List<Map>list = service.selectBySexCount();
        return list;
    }
    @RequestMapping("selectByProvince")
    @ResponseBody
    public List<Map> selectByProvince(){
        List<Map> list = service.selectByProvince();
        for (Map map : list) {
            System.out.println(map);
        }
        return list;
    }
    @RequestMapping("selectByDayCount")
    @ResponseBody
    public Map selectByDayCount(){
        Map map = service.selectByDayCount();
        return map;
    }

    @RequestMapping("getAllData")
    @ResponseBody
    public Map getAllData() throws Exception {
        Map map = threadUserService.getAllCountByCountDownLatch();
        return map;
    }
}
